﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration; 
using System.Data.SqlClient;

namespace LOGIN
{
    public partial class InputtotalTable : Form
    {
        public InputtotalTable()
        {
            InitializeComponent();
            this.dgv_InputtotalTable.AllowUserToAddRows = false;

        }
        private DataTable ordersTable;

        private void InputtotalTable_Load(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString =
                "Server=(local);Database=MyHospital;Integrated Security=sspi";
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandText = "select OrderID,SupplyID,OrderKinds,OrderDate,cs.IndPrice,Num,GetDate,ProducePla,State,c.DrugName,TolPrice,cs.Guige,dbo.fn_GetPy(DrugName) AS pymc FROM orders cs JOIN dbo.medicineData c ON cs.MedicineID=c.MedicineID WHERE State='1';";
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            sqlDataAdapter.SelectCommand = sqlCommand;
            this.ordersTable = new DataTable();

            sqlConnection.Open();

            sqlDataAdapter.Fill(ordersTable);

            sqlConnection.Close();

            this.dgv_InputtotalTable.DataSource = ordersTable;
            dgv_InputtotalTable.Columns["OrderID"].ReadOnly = true;
            dgv_InputtotalTable.Columns["OrderKinds"].ReadOnly = true;
            dgv_InputtotalTable.Columns["OrderID"].HeaderText = "订单号";
            dgv_InputtotalTable.Columns["SupplyID"].Visible = false;
            dgv_InputtotalTable.Columns["OrderKinds"].HeaderText = "订单";
            dgv_InputtotalTable.Columns["OrderDate"].HeaderText = "订单日期";
            dgv_InputtotalTable.Columns["GetDate"].HeaderText = "到货日期";
            dgv_InputtotalTable.Columns["ProducePla"].HeaderText = "生产地";
            dgv_InputtotalTable.Columns["State"].HeaderText = "是否入库";
            dgv_InputtotalTable.Columns["DrugName"].HeaderText = "药品";
            dgv_InputtotalTable.Columns["IndPrice"].HeaderText = "单价";
            dgv_InputtotalTable.Columns["Num"].HeaderText = "数量";
            dgv_InputtotalTable.Columns["TolPrice"].HeaderText = "总价";
            dgv_InputtotalTable.Columns["Guige"].HeaderText = "规格";
            dgv_InputtotalTable.Columns["pymc"].Visible = false;
            this.dgv_InputtotalTable.Columns[this.dgv_InputtotalTable.Columns.Count - 1].AutoSizeMode =
                DataGridViewAutoSizeColumnMode.Fill;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            DataRow[] searchResultRows =
                this.ordersTable.Select("pymc LIKE '%" + this.textBox1.Text.Trim() + "%'");           
            DataTable searchResultTable = this.ordersTable.Clone();                                         
            foreach (DataRow row in searchResultRows)                                                       
            {
                searchResultTable.ImportRow(row);                                                       
            }
            this.dgv_InputtotalTable.DataSource = searchResultTable;

        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            DataRow[] searchResultRows =
                this.ordersTable.Select("", "Num asc");             
            DataTable searchResultTable = this.ordersTable.Clone();                                
            foreach (DataRow row in searchResultRows)                                          
            {
                searchResultTable.ImportRow(row);                                                        
            }
            this.dgv_InputtotalTable.DataSource = searchResultTable; 
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            DataRow[] searchResultRows =
               this.ordersTable.Select("", "IndPrice asc");
            DataTable searchResultTable = this.ordersTable.Clone();
            foreach (DataRow row in searchResultRows)
            {
                searchResultTable.ImportRow(row);
            }
            this.dgv_InputtotalTable.DataSource = searchResultTable; 
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
      



    }
}
